﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Shell;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Collections;
using System.Globalization;

namespace Sharp.UnusedReferences.Options
{
	[ClassInterface(ClassInterfaceType.AutoDual)]
	public class DialogPageOptionsGeneral : DialogPage
	{
		#region Fields

		DateTimeFormatInfo DateTimeFormatInfoInstance;

		internal const string ScanBuildableProjectsOnly_DisplayName = "Scan buildable projects only";
		internal const string IncludeSelectionInExportedFile_DisplayName = "Include selection in exported file";
		internal const string ReportDateFormat_DisplayName = "Report date format";
		internal const string ReportTimeFormat_DisplayName = "Report time format";

		private const bool ScanBuildableProjectsOnly_Default = true;
		private const bool IncludeSelectionInExportedFile_Default = false;
		private const string ReportDateFormat_Default = "dddd dd MMMM yyyy";
		private const string ReportTimeFormat_Default = "hh:mm:ss tt";

		#endregion

		#region Constructors

		public DialogPageOptionsGeneral()
		{
			DateTimeFormatInfoInstance = new DateTimeFormatInfo();
			ScanBuildableProjectsOnly = ScanBuildableProjectsOnly_Default;
			IncludeSelectionInExportedFile = IncludeSelectionInExportedFile_Default;
			ReportDateFormat = ReportDateFormat_Default;
			ReportTimeFormat = ReportTimeFormat_Default;
		}

		#endregion

		#region Properties

		[Category("Scanning")]
		[DisplayName(ScanBuildableProjectsOnly_DisplayName)]
		[Description("Controls weather to scan the projects which are marked as \"Build\" in \"Solution Configurations\" only or scan all the projects.")]
		[DefaultValue(ScanBuildableProjectsOnly_Default)]
		public bool ScanBuildableProjectsOnly
		{
			get;
			set;
		}

		[Category("Reporting")]
		[DisplayName(IncludeSelectionInExportedFile_DisplayName)]
		[Description("Controls weather to show the check boxes and current selection in the tree view of the exported file or not.")]
		[DefaultValue(IncludeSelectionInExportedFile_Default)]
		public bool IncludeSelectionInExportedFile
		{
			get;
			set;
		}

		[Category("Reporting")]
		[DisplayName(ReportDateFormat_DisplayName)]
		[Description("Specifies the format by which the report creation date will be displayed in the report.")]
		[DefaultValue(ReportDateFormat_Default)]
		public string ReportDateFormat
		{
			get
			{
				return DateTimeFormatInfoInstance.ShortDatePattern;
			}
			set
			{
				DateTimeFormatInfoInstance.ShortDatePattern = value;
				TypeDescriptor.Refresh(this);
			}
		}

		[Browsable(true)]
		[ReadOnly(true)]
		[Category("Reporting")]
		[DisplayName("Report date format preview")]
		[Description("Preview the Report date format using current date.")]
		public string ReportDateFormatPreview
		{
			get
			{
				return DateTime.Now.ToString(ReportDateFormat, DateTimeFormatInfoInstance);
			}
		}

		[Category("Reporting")]
		[DisplayName(ReportTimeFormat_DisplayName)]
		[Description("Specifies the format by which the report creation time will be displayed in the report.")]
		[DefaultValue(ReportTimeFormat_Default)]
		public string ReportTimeFormat
		{
			get
			{
				return DateTimeFormatInfoInstance.ShortTimePattern;
			}
			set
			{
				DateTimeFormatInfoInstance.ShortTimePattern = value;
				TypeDescriptor.Refresh(this);
			}
		}

		[Browsable(true)]
		[ReadOnly(true)]
		[Category("Reporting")]
		[DisplayName("Report time format preview")]
		[Description("Preview the Report time format using current time.")]
		public string ReportTimeFormatPreview
		{
			get
			{
				return DateTime.Now.ToString(ReportTimeFormat, DateTimeFormatInfoInstance);
			}
		}

		#endregion

		#region Public Functions
		
		internal Hashtable GetSettingsForDisplay(SettingsCategory Category)
		{
			Hashtable HashtableResult = new Hashtable();
			if(Category == SettingsCategory.Scanning)
			{
				HashtableResult.Add(ScanBuildableProjectsOnly_DisplayName, ScanBuildableProjectsOnly ? "Yes" : "No");
			}
			if(Category == SettingsCategory.Reporting)
			{
				HashtableResult.Add(IncludeSelectionInExportedFile_DisplayName, IncludeSelectionInExportedFile ? "Yes" : "No");
				HashtableResult.Add(ReportDateFormat_DisplayName, ReportDateFormat);
				HashtableResult.Add(ReportTimeFormat_DisplayName, ReportTimeFormat);
			}
			return HashtableResult;
		}
		internal string ToDateString(DateTime DateTimeInstance)
		{
			return DateTimeInstance.ToString(ReportDateFormat, DateTimeFormatInfoInstance);
		}
		internal string ToTimeString(DateTime DateTimeInstance)
		{
			return DateTimeInstance.ToString(ReportTimeFormat, DateTimeFormatInfoInstance);
		}

		#endregion
	}
}
